import 'package:lib_bt/bean/BleBeanInterface.dart';
import 'package:lib_util/ByteUtils.dart';

import '../base/LedBleBeanInterface.dart';

class BleBean extends LedBleBeanInterface {
  BleBean({BleBeanInterface? bean}) {
    if (bean != null) {
      bytes = bean.bytes;
      address = bean.address;
      name = bean.name;
      rssi = bean.rssi;
      isConnect = bean.isConnect;
      mtu = bean.mtu;
      mac = bean.mac;
    }
  }

  ///获取屏幕宽度
  @override
  int get width {
    return ByteUtils.byte2Short([bytes[7], bytes[8]]);
  }

  ///获取屏幕高度
  @override
  int get height {
    return ByteUtils.byte2Short([bytes[5], bytes[6]]);
  }

  ///固件版本号
  @override
  int get versionCode {
    return ByteUtils.byte2Short([bytes[11], bytes[12]]);
  }

  //客户id,一个编码值而已
  @override
  int get customerId {
    return ByteUtils.byte2Short([bytes[13], bytes[14]]);
  }

  ///屏幕色彩类型
  @override
  int get screenColorType {
    return bytes[9];
  }

  //是否是单色
  bool isSingleColor(){
    return screenColorType == 0 || screenColorType == 1;
  }

  ///屏幕类型识别码
  @override
  int get screenTypeId {
    return ByteUtils.byte2Int([bytes[1], bytes[2], bytes[3], bytes[4]]);
  }

  int get funCode {
    return ByteUtils.byte2Short([bytes[15], bytes[16]]);
  }

  /// 是否支持时间显示
  bool get isSupportTime {
    return funCode & 0x01 != 0;
  }

  ///是否支持分区
  bool get isSupportPartition {
    return funCode & 0x02 != 0;
  }

  ///是否支持解析gif文件
  bool get isSupportGif {
    return funCode & 0x04 != 0;
  }

  ///是否支持多媒体节目
  bool get isSupportMedia {
    return funCode & 0x08 != 0;
  }

  ///是否有旋转功能
  bool get isSupportRotate {
    return funCode & 0x10 != 0;
  }

  ///是否支持边框功能
  bool get isSupportBorder {
    return funCode & 0x20 != 0;
  }

  ///是否支持密码功能
  bool get isSupportPassword {
    return funCode & 0x40 != 0;
  }

  ///是否支持遥控功能
  bool get isSupportRemote {
    return funCode & 0x80 != 0;
  }

  ///是否支持左右眼遥控
  bool get isSupportEye {
    return funCode & 0x10 != 0;
  }

  ///是否支持亮度调节
  bool get isSupportBrightness {
    return versionCode >= 6;
  }
}
